﻿// <copyright file="MainWindow.xaml.cs" company="NorthCoast NERO">
//     NorthCoast NERO. All rights reserved.
// </copyright>
// <author>Eric Kociecki</author>
namespace NcnPlayerCheckIn
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Globalization;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Controls.Primitives;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using NcnPlayerCheckIn.Controls;

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public sealed partial class MainWindow : Window
    {
        /// <summary>
        /// Initializes a new instance of the MainWindow class.  Initializes XAML-defined objects.
        /// </summary>
        public MainWindow()
        {
            this.InitializeComponent();

            // reads version from assembly info and displays it in UI
            this.versionDisplay.Content = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

            // attempt to read in the current event data
            try
            {
                this.PlayerList = FileWriter.ReadFile();
            }
            catch
            {
                this.PlayerList = new Collection<Player>(new List<Player>());
            }

            this.playerListPanel.ParentWindow = this;
            this.statsPanel.ParentWindow = this;
        }

        /// <summary>
        /// Gets or sets a list of all Players that have checked in at this event (some may have also checked out, but they are still tracked here).
        /// </summary>
        public Collection<Player> PlayerList { get; set; }

        /// <summary>
        /// Event handler for tabControl SelectionChanged event.  This handles extra tasks that must be completed when switching tabs.
        /// </summary>
        /// <param name="sender">The control that fired the event.</param>
        /// <param name="e">EventArgs related to the event.</param>
        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.Source is TabControl)
            {
                if (this.checkInTab.IsSelected)
                {
                    this.playerListPanel.UpdatePlayerDisplay();
                }
                else if (this.statsTab.IsSelected)
                {
                    this.statsPanel.UpdateStats();
                }
                else if (this.maintenanceTab.IsSelected)
                {
                    ////placeholder
                }

                FileWriter.WriteFile(this.PlayerList);
            }
        }
    }
}
